﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using System.Windows.Controls;

namespace Hugo.UIPages
{
    class MoviePlayerUIPage : UIPage
    {
        //<MediaElement Name="mediaElement" LoadedBehavior="Manual" UnloadedBehavior="Stop"
        //         MediaOpened="MediaElement_MediaOpened" MediaEnded="MediaElement_MediaEnded" Position="00:00:30" />

        MediaElement me;

        public MoviePlayerUIPage(String name, BitmapSource s, String uri) : base(name,s)
        {
            me = new MediaElement();
            me.LoadedBehavior = MediaState.Manual;
            me.UnloadedBehavior = MediaState.Stop;
            me.MediaOpened += new System.Windows.RoutedEventHandler(MediaElement_MediaOpened);
            me.MediaEnded += new System.Windows.RoutedEventHandler(MediaElement_MediaEnded);
            me.Stretch = System.Windows.Media.Stretch.Fill;
            me.Source = new Uri(uri);

            Grid g = new Grid();
            g.Margin = new System.Windows.Thickness(0,0,0,0);
            g.Width = GlobalSettings.ScreenMiddleX*2;
            g.Height = GlobalSettings.ScreenMiddleY*2;
            this.PageCanvas.Children.Add(g);
            g.Children.Add(me);
        }

        private void MediaElement_MediaOpened(object sender, System.Windows.RoutedEventArgs e)
        {
        }

        private void MediaElement_MediaEnded(object sender, EventArgs e)
        {
            me.Stop();
        }

        public override void setPage()
        {
            me.Play();
            base.setPage();
        }

        public override void  unSetPage()
        {
             me.Pause();
 	         base.unSetPage();
        }

    }
}
